#ifndef __SINGLETON_H__
#define __SINGLETON_H__

/// @brief 单例懒汉式
class CSingletonLazy
{
public:
    /// @brief 获取全局唯一实例化对象
    /// @return 对象指针
    static CSingletonLazy *GetInstance()
    {
        static CSingletonLazy m_instance; // C++11以后：静态局部变量是线程安全的
        return &m_instance;
    }

protected:
    CSingletonLazy() = default;
    CSingletonLazy(const CSingletonLazy &) = delete;
    CSingletonLazy &operator=(const CSingletonLazy &) = delete;
};
/// @brief 单例饿汉式
class CSingletonHungry
{
public:
    static CSingletonHungry *GetInstance()
    {
        return &m_instance;
    }

protected:
    /// @brief 饿汉式助手类，主要用于在类是在堆上申请内存时，无法释放的问题
    /* class CSingletonHungryHelper
    {
    public:
        CSingletonHungryHelper()
        {
            m_instance = new CSingletonHungry;
        }
        ~CSingletonHungryHelper()
        {
            delete m_instance;
        }
        CSingletonHungry *m_instance{};
    };
    static CSingletonHungryHelper m_helper; */

    static CSingletonHungry m_instance;

protected:
    CSingletonHungry() = default;
    CSingletonHungry(const CSingletonHungry &) = delete;
    CSingletonHungry &operator=(const CSingletonHungry &) = delete;
};

// CSingletonHungry::CSingletonHungryHelper CSingletonHungry::m_helper;

CSingletonHungry CSingletonHungry::m_instance;

#endif
